Created On: 15 February 2011
Problem:
Say that XML GENERATE is being used to create XML for the following:
01 XML-DATA.
03 XML-DATA-REC.
05 XML-DATA-DETAIL OCCURS 100.
07 XML-NUMBER PIC X(04).
07 XML-STRING PIC X(40).
When only 3 rows are filled in the table and the following is used:
XML GENERATE WS-XML-DATA FROM XML-DATA
COUNT IN WS-XML-COUNT
WITH XML-DECLARATION
You will get the following result :
0001TEST10002TEST20003TEST3
...
Can XML be generated without the empty fields from the table?
01 XML-DATA.
03 XML-DATA-REC.
05 XML-DATA-DETAIL OCCURS 100.
07 XML-NUMBER PIC X(04).
07 XML-STRING PIC X(40).
When only 3 rows are filled in the table and the following is used:
XML GENERATE WS-XML-DATA FROM XML-DATA
COUNT IN WS-XML-COUNT
WITH XML-DECLARATION
You will get the following result :
0001TEST10002TEST20003TEST3
...
Can XML be generated without the empty fields from the table?
Resolution:
XML GENERATE General Rule 8 states:
If a character value consists only of spaces, one space remains as the value after trimming is finished.
In order to remove the blank tags you can use an Occurs Depending On to limit the scope of the data items used.
The following will result in only the 3 tags that you want:
If a character value consists only of spaces, one space remains as the value after trimming is finished.
In order to remove the blank tags you can use an Occurs Depending On to limit the scope of the data items used.
The following will result in only the 3 tags that you want:
Code:
working-storage section.
01 XML-DATA.
03 XML-DATA-REC.
05 XML-DATA-DETAIL OCCURS 1 to 100 depending on ws-count.
07 XML-NUMBER PIC X(04).
07 XML-STRING PIC X(40).
01 ws-count pic 9(3) value 3.
01 ws-xml-count pic 9(9).
01 ws-xml-data pic x(5000) value spaces.
procedure division.
move "0001" to xml-number(1)
move "TEST1" to xml-string(1)
move "0002" to xml-number(2)
move "TEST2" to xml-string(2)
move "0003" to xml-number(3)
move "TEST3" to xml-string(3)
move 3 to ws-count
XML GENERATE WS-XML-DATA FROM XML-DATA
COUNT IN WS-XML-COUNT
WITH XML-DECLARATION
Old KB# 33370
#netexpress
#COBOL
#Enterprise
#VisualCOBOL