‎2008 Jun 13 10:19 AM
Ok so this is my code.
REPORT ZISTANZS_TRNG_EX9A_CUST.
TABLES: KNA1.
DATA: BEGIN OF FS,
CusNum LIKE KNA1-KUNNR,
Name LIKE KNA1-NAME1,
SrchTerm LIKE KNA1-SORTL,
City LIKE KNA1-ORT01,
Postal LIKE KNA1-PSTLZ,
Country LIKE KNA1-LAND1,
Language LIKE KNA1-SPRAS,
END OF FS.
PARAMETERS: Filename(30) TYPE C OBLIGATORY LOWER CASE,
CusNum LIKE KNA1-KUNNR OBLIGATORY,
Name LIKE KNA1-NAME1 OBLIGATORY,
SrchTerm LIKE KNA1-SORTL OBLIGATORY,
City LIKE KNA1-ORT01 OBLIGATORY,
Postal LIKE KNA1-PSTLZ OBLIGATORY,
Country LIKE KNA1-LAND1 OBLIGATORY,
Language LIKE KNA1-SPRAS OBLIGATORY.
PARAMETERS: Create RADIOBUTTON GROUP G1,
Append RADIOBUTTON GROUP G1.
IF Create = 'X'.
OPEN DATASET Filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
FS-CusNum = CusNum.
FS-Name = Name.
FS-SrchTerm = SrchTerm.
FS-City = City.
FS-Postal = Postal.
FS-Country = Country.
FS-Language = Language.
TRANSFER FS to Filename.
CLOSE DATASET Filename.
ELSEIF Append = 'X'.
OPEN DATASET Filename FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
FS-CusNum = CusNum.
FS-Name = Name.
FS-SrchTerm = SrchTerm.
FS-City = City.
FS-Postal = Postal.
FS-Country = Country.
FS-Language = Language.
TRANSFER FS to Filename.
CLOSE DATASET Filename.
ENDIF.
-
My problem is whenever I open the file in which it was 'created' or 'appended' to. It's in telnet btw. the fields are so messy, I got 0000 first then my custoemr number, then after a few spaces I see the name and after about 10 spaces the search term and all that. Everything's one big pile of mess. Is there something wrong witht he way I transfer data to the file? And what's with that 0000 at the start of the file?
‎2008 Jun 13 10:29 AM
Hi,
After open dataset, just check for sy-subrc.
if sy-subrc = 0 , now check the contents and please give proper information.
Regards,
‎2008 Jun 13 10:52 AM
Hi zsa tan,
except from unnecessary code redundancy and confusing field names everything looks fine.
Maybe you do not know that the KUNNR's internal representation is with leading zeros. In debugger you can see it. Here's you code just a little bit abbreviated (don't forget to enclose code sequences in \
... \.
I do not know what you mean by 'big pile of mess'. Count the characters and see what deviations you get. I suppose it works as desired.
REPORT ZISTANZS_TRNG_EX9A_CUST.
TABLES: KNA1.
DATA: BEGIN OF FS,
CusNum LIKE KNA1-KUNNR,
Name LIKE KNA1-NAME1,
SrchTerm LIKE KNA1-SORTL,
City LIKE KNA1-ORT01,
Postal LIKE KNA1-PSTLZ,
Country LIKE KNA1-LAND1,
Language LIKE KNA1-SPRAS,
END OF FS.
PARAMETERS: Filename(30) TYPE C OBLIGATORY LOWER CASE,
CusNum LIKE KNA1-KUNNR OBLIGATORY,
Name LIKE KNA1-NAME1 OBLIGATORY,
SrchTerm LIKE KNA1-SORTL OBLIGATORY,
City LIKE KNA1-ORT01 OBLIGATORY,
Postal LIKE KNA1-PSTLZ OBLIGATORY,
Country LIKE KNA1-LAND1 OBLIGATORY,
Language LIKE KNA1-SPRAS OBLIGATORY.
PARAMETERS: Create RADIOBUTTON GROUP G1,
Append RADIOBUTTON GROUP G1.
IF Create = 'X'.
OPEN DATASET Filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
ELSE.
OPEN DATASET Filename FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
endif.
FS-CusNum = CusNum.
FS-Name = Name.
FS-SrchTerm = SrchTerm.
FS-City = City.
FS-Postal = Postal.
FS-Country = Country.
FS-Language = Language.
TRANSFER FS to Filename.
CLOSE DATASET Filename.
Regards,
Clemens