Commodore
Commodore
1764 views

01 wOqueBuscar pic x(500).

move  "<ns3:Numero>" to wOqueBuscar.

I'm reading a file and checking if a particular condition is found in this file, I'm not sure if I'm doing something wrong but so does!

inspect reg-sai tallying wCol for all "<ns3:Numero>"

and so does not!


inspect reg-sai tallying wCol2 for all wOqueBuscar

Have any way to look for a string inside another?

Eu estou lendo um arquivo e verificar se um determinada condição é encontrada neste arquivo, não sei se estou fazendo algo errado mas assim funciona,

inspect reg-sai tallying wCol for all "<ns3:Numero>" 

e assim não! tem alguma forma de procurar uma string dentro de outra?

inspect reg-sai tallying wCol2 for all wOqueBuscar 

 

Translated by Google
0 Likes
2 Solutions

Accepted Solutions
Absent Member.
Absent Member.
The trailing spaces in wOqueBuscar would be part of the search. You will need to use reference modification as in wOqueBuscar(1:12) to limit the search to the 12 characters of "<ns3:Numero>" instead of all 500 characters in wOqueBuscar.

View solution in original post

0 Likes
Absent Member.
Absent Member.
The reference modification is suggested for the search string, not the inspected string. Thus the 1 means the first character of the search string, not the first character in the inspected string. The reference modification length can be a variable, but you will need to set it to the length of the search string, which you must know or determine in some way (possibly with an inspect statement to count the trailing spaces and subtract that from the length of wOqueBuscar).

move "<ns3:IdentificacaoNfse>" to wOqueBuscar
move 23 to search-length
inspect reg-sai tallying wTem for all wOqueBuscar(1:search-length)

View solution in original post

0 Likes
9 Replies
Micro Focus Expert
Micro Focus Expert
Your second example will be looking for occurrences of "<ns3:Numero> ..." (i.e. the text followed by 488 spaces), which I assume will not be found in reg-sai.
Probably easiest to use reference modification, something like:

inspect reg-sai tallying wCol2 for all wOqueBuscar(1:12)
0 Likes
Absent Member.
Absent Member.
The trailing spaces in wOqueBuscar would be part of the search. You will need to use reference modification as in wOqueBuscar(1:12) to limit the search to the 12 characters of "<ns3:Numero>" instead of all 500 characters in wOqueBuscar.

View solution in original post

0 Likes
Commodore
Commodore
But the string I'm looking for may not be in position 1 and this string can also have a larger number of characters.

inspect reg-sai tallying wTem for all "<ns3:IdentificacaoNfse>"
0 Likes
Absent Member.
Absent Member.
The reference modification is suggested for the search string, not the inspected string. Thus the 1 means the first character of the search string, not the first character in the inspected string. The reference modification length can be a variable, but you will need to set it to the length of the search string, which you must know or determine in some way (possibly with an inspect statement to count the trailing spaces and subtract that from the length of wOqueBuscar).

move "<ns3:IdentificacaoNfse>" to wOqueBuscar
move 23 to search-length
inspect reg-sai tallying wTem for all wOqueBuscar(1:search-length)

View solution in original post

0 Likes
Commodore
Commodore
Many thanks to the past tips I did this routine!

77 wPosInicial pic 9(003).
77 wTamTotal pic 9(003).
77 wPosFinal pic 9(003).
77 wTem pic 9(003).
77 wOqueBuscar string.
77 wTextoEncontrado pic x(500).
77 wReg pic x(100).




move "<ns3:Numero>" to wOqueBuscar wTextoEncontrado
perform LocalizaCampo


LocalizaCampo.
set wPosInicial to wOqueBuscar::Length
set wTem to zeros
perform until wTem > 0 or wFim = 1
set wReg to reg-sai::Trim
inspect wReg tallying wTem for all wTextoEncontrado(1:wPosInicial)
read saida at end move 1 to wFim end-read
end-perform
set wTextoEncontrado to wReg
set wOqueBuscar to wTextoEncontrado::Trim *> aqui vem <tag> e <\tag>
set wTamTotal to wOqueBuscar::Length
set wPosFinal to wOqueBuscar::IndexOf("</")
if wPosFinal > 1
add 1 to wPosFinal
set wTexto to wTextoEncontrado(wPosInicial + 1: wPosFinal - (wPosInicial + 1))
end-if.
0 Likes
Knowledge Partner Knowledge Partner
Knowledge Partner

My comment is based on the issue of trying to parse XML in COBOL.  I draw this conclusion from the example.  

Using COBOL to parse a specific XML document is a very difficult task.  (I am not commenting on the task of writing a generalized XML parser in Visual COBOL, because that can be done.  The example shows that a generalized parser is not the goal.)  During my career I have seen (literally) thousands of lines of XML parsing code rendered inoperable by simple changes in XML documents.

Just to use the example, in this particular document instance, the XML tag is "<ns3:Numero>".  However, in a subsequent document, the identical tag may be coded as "<ns5:Numero>" and still be perfectly valid XML.  The reason for this is that the "ns3" portion is a namespace alias, and the association of the namespace alias and its namespace string value is local to the document.  When a namespace is specified for an element (for example, in a web services WSDL), the namespace value is specified, not the alias.  The process producing the document is free to use whatever namespace alias it chooses.  If you 'hard code' "ns3" in your search, your search will fail if the process producing the document selects a different namespace alias.

There are other difficulties in parsing XML as well.  XML documents may or may not contain whitespace (line feeds) to improve human readability, but extraneous whitespace characters are usually not transmitted with a document that is not intended for human reading.

There are several possible solutions, including some Visual COBOL language features that allow XML processing  while relieving you from having to parse XML.  Alternatively, you can preprocess the document using XSL to produce a flat sequential file containing the data extracted in a manner that can be more easily consumed by a COBOL program.


Tom Morrison
Consultant

0 Likes
Commodore
Commodore
Very good explanation, but there was no other way, or at least I did not find a way to do this reading, live programming in Cobol is the language I master, and here in Brazil we have some programmers but for Visual Cobol tools are rare , so I have to unfold myself, our terms have a different meaning in English. But thanks for the tips!

Translated by Google

Muito boa explanação, mas não havia outra forma, ou pelo menos, eu não encontrei uma forma de fazer esta leitura, vivo de programação em Cobol é a linguagem que domino, e aqui no Brasil temos alguns programadores mas para a ferramente Visual Cobol são raros, então tenho que me desdobrar, termos nossos ficam com outro sentido no inglês. Mas obrigado pelas dicas!

Traduzido pelo Google
0 Likes
Knowledge Partner Knowledge Partner
Knowledge Partner

You can use a process external to COBOL to convert the XML to a sequential text file before processing the data with COBOL.  The tool for doing this is XSLT.  See https://es.wikipedia.org/wiki/Extensible_Stylesheet_Language_Transformations as a starting point for some tutorials.   Many XSLT tutorials emphasize converting XML to HTML, or converting XML to a different XML document, but it is also possible to convert XML to sequential text file (using the <xsl:output> directive).  There are several freely available XML/XSLT processors for Windows, Linux and Unix systems.

By using such a conversion strategy, you can control the format of the sequential text file, and isolate the COBOL program from changes in the incoming XML document.  (XML documents used in electronic commerce go through version changes in much the same way that computer software goes through version changes.)

I am not bilingual in Spanish (at least for a detailed technical discussion), but there are several such people on the Micro Focus Community, should we need such assistance.


Tom Morrison
Consultant

0 Likes
Absent Member.
Absent Member.

Just a thought.... Another option is to use the power of SQL which includes regular expressions and so on. If for example you had MySQL running on the machine and set up cobol to work with sql, you could do things like...

NOT TESTED!!! ...

01 my-result pic 9.
88 string-found value 1.
01 my-search-string pic x(100).
01 my-big-field pic x(1000).
...
exec sql
select case when :my-big-field like concat('%', trim(:my-search-string), '%') then 1 else 0 end
into :my-result
from dual *> dual is MySQL dummy table
end-exec.

Linden Rowland - IT Consultant
Owner/Developer, www.SchoolReportWriter.com
IT Consultant to Tindle Newspaper Group

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.