Focal Point
[SOLVED] Concatenate a MDYY field with a numeric field

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/3497009336

October 03, 2013, 04:37 PM
Josh K
[SOLVED] Concatenate a MDYY field with a numeric field
I want to concatenate a MDYY field with a numeric field that represents the time of day.

This is what I'm doing. I know the date field has a value of 10032013 (since I specified it in the where clause) but the result I am getting is "00041184 004426" The time part is right, but the date part has been mutated somehow.

  DEFINE FILE F554852
ZZZ/A15 = EDIT(TLCRDJ,'99999999') | ' ' | EDIT(TLTDAY);
END
-RUN

TABLE FILE F554852
PRINT ZZZ
TLCRDJ 
TLTDAY  
BY TLCRDJ NOPRINT
BY TLTDAY  NOPRINT
WHERE  TLCRDJ EQ '10032013'
 ON TABLE PCHOLD FORMAT EXCEL
END

This message has been edited. Last edited by: <Kathryn Henning>,


WebFOCUS 7.6.9
Windows
all output (Excel, HTML, PDF)
October 03, 2013, 04:53 PM
Waz
What format is the field TLCRDJ ?

HAve you thought about using a DateTime field instead ?


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

October 03, 2013, 04:55 PM
Josh K
FIELD=TLCRDJ,
ALIAS=TLCRDJ, USAGE=MDYY , ACTUAL=DATE,
DESCRIPTION='Creation Date.',
TITLE='Creation Date.',$

This is an old db4 database. The date is actually stored as a numeric field in JDE Julian format in the database. But Webfocus is already converting it to MDYY.


WebFOCUS 7.6.9
Windows
all output (Excel, HTML, PDF)
October 03, 2013, 05:00 PM
MReeder
It would be much easier to convert the TLTDAY to a timestamp and make ZZZ a DateTime value.

Is there some reason why you need it as an alpha character?


WebFOCUS 8.2.02M
Windows
Server/8.2.02M
All Outputs
October 03, 2013, 05:03 PM
Josh K
Not really. Can I do this in the report without having to change the masterfiles?


WebFOCUS 7.6.9
Windows
all output (Excel, HTML, PDF)
October 03, 2013, 05:26 PM
Waz
As TLCRDJ is MDYY, you can convert it to alpha first.

MDYYTLCRDJ/A8MDYY = TLCRDJ ;
ZZ/A15 = MDYYTLCRDJ | ' ' | EDIT(TLTDAY); 


You could also use the H function to convert to timestamp.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

October 03, 2013, 05:28 PM
Francis Mariani
DEFINE FILE CAR
-* YOUR FIELDS
TLCRDJ/MDYY = '10/03/2013';
TLTDAY/I6 = 004426;

-* CONVERT TO ALPHA
TLCRDJA/A8YYMD = TLCRDJ;
TLTDAYA/A8 = EDIT(TLTDAY,'99:99:99');
TLTDTTMX/A25 = TLCRDJA | ' ' | TLTDAYA;

-* CONVERT TO DATE-TIME
TLTDTTM/HMDYYS = HINPUT(25, TLTDTTMX, 8, 'HYYMDS');
END

TABLE FILE CAR
PRINT 
TLCRDJ
TLCRDJA
TLTDAY
TLTDAYA
TLTDTTM
COUNTRY NOPRINT
WHERE RECORDLIMIT EQ 1
ON TABLE PCHOLD FORMAT EXL2K
END



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
October 03, 2013, 05:58 PM
Josh K
Is there a way to take a snippet of code like that and make it into a function?

This message has been edited. Last edited by: Josh K,


WebFOCUS 7.6.9
Windows
all output (Excel, HTML, PDF)
October 03, 2013, 06:09 PM
Waz
Yes


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

October 03, 2013, 06:15 PM
Josh K
I've tried to make Francis' example use a defined function, but I am getting an error.


     (FOC239) FORMAT DEFINITION IN ERROR. INTERNAL FIELD: DTDP
    BYPASSING TO END OF COMMAND
  0 ERROR AT OR NEAR LINE     34  IN PROCEDURE _ADHOCRQFOCEXEC * 
   (FOC263) EXTERNAL FUNCTION OR LOAD MODULE NOT FOUND: ALPHADT
  0 ERROR AT OR NEAR LINE     40  IN PROCEDURE _ADHOCRQFOCEXEC * 
   (FOC003) THE FIELDNAME IS NOT RECOGNIZED: TLTDTTMX
    BYPASSING TO END OF COMMAND
   (FOC009) INCOMPLETE REQUEST STATEMENT

The code:

 


 DEFINE FUNCTION ALPHADT (DTDP/MDYY, TMPT/I6)
-* CONVERT TO ALPHA
TLCRDJA/A8YYMD = DTDP;
TLTDAYA/A8 = EDIT(TMPT,'99:99:99');
TLTDTTMX/A25 = TLCRDJA | ' ' | TLTDAYA;

-* CONVERT TO DATE-TIME
TLTDTTM/HMDYYS = HINPUT(25, TLTDTTMX, 8, 'HYYMDS');

ALPHADT/A25 = TLTDTTMX;
END


DEFINE FILE CAR
-* YOUR FIELDS
TLCRDJ/MDYY = '10/03/2013';
TLTDAY/I6 = 004426;

TLTDTTMX/A25 = ALPHADT( TLCRDJ, TLTDAY );

END

TABLE FILE CAR
PRINT
TLCRDJ
TLTDAY
TLTDTTMX
COUNTRY NOPRINT
WHERE RECORDLIMIT EQ 1
-*ON TABLE PCHOLD FORMAT EXL2K
 ON TABLE PCHOLD FORMAT EXCEL
END
 



WebFOCUS 7.6.9
Windows
all output (Excel, HTML, PDF)
October 03, 2013, 06:39 PM
Waz
Well first thing, you are trying to put MDYY into an A8YYMD, Change the format of DTDP to YYMD, and try


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

October 03, 2013, 06:43 PM
Josh K
Putting a MDYY into an A8YYMD actually works. What apparently doesn't work is using a MDYY or YYMD as a parameter to a defined function. If I put the MDYY in the A8YYMD first and then send the A8YYMD to the function it works fine.


WebFOCUS 7.6.9
Windows
all output (Excel, HTML, PDF)
October 03, 2013, 06:57 PM
Waz
I would strongly suggest that you pass though all matching formats.

Also, the technique you use to convert your time field from I6 to A8 is not a safe or future proof method.

You should convert from I to A, then add the colons.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!