Trimming just one leading zero (if present) in SQLRPGLE

5 pts.
Tags:
IBM iSeries
OS/400
SQLRPGLE
I have a SQLRPGLE program and have 6A character field. How to I trim just one leading zero(if present) Eg- if 001300 then I should insert 01300. Thanks!

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 21  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    if 001300 then I should insert 01300 What if the value is {1300}? Should you still insert {01300}? What if the value is {b01300}? What if the value is {00001300}? Overall, the conditions aren't clear at all. What kind of values are you working with? Fixed or variable? (Chyaracter or numeric?) Are you trying to generate an INSERT statement or do you have a prepared INSERT statement with :program variables? Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    In the RPG code you can drop the leading zero like this .. in Free format if %SubSt(InStr:1:1) = 0; InStr = %SUBST(InStr:2:7); Endif; Phil
    49,950 pointsBadges:
    report
  • TomLiotta
    if %SubSt(InStr:1:1) = 0; Note that that would also trim the zero from "01300". Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    if %SubSt(InStr:1:1) = '0'; InStr = %SUBST(InStr:2:7); Endif; Correction -- needed ' ' around the zero This may not be what they really want, but it's exactly what they asked for. Phil
    49,950 pointsBadges:
    report
  • TomLiotta
    it’s exactly what they asked for. I agree. It can be harder trying to find out what is needed than supplying an answer to a question. Questions get dropped into here, and the original poster just disappears. It's easy enough to supply a simple solution that always removes a single leading zero, as your solution does. And it's just about as easy to remove multiple leading zeroes to arrive at a specific result length such as five characters, e.g., '01300', regardless of what the input was. But when the OP disappears, the whole question might be wasted. We can't even tell if it was ever looked at again. Hmmm... I wonder if that could be automated? Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    There is nothing for it. So many only ask one question or make a new profile for each question, we don't know their resources and cannot answer their questions at the correct level. The questions are often vague and they don't respond to our questions, suggestions often. Phil
    49,950 pointsBadges:
    report
  • Michael Morisy
    "So many only ask one question or make a new profile for each question, we don’t know their resources and cannot answer their questions at the correct level." I wish there was something we could do about this ... If they give us their real e-mail, users get pinged when there is an update but sometimes that's not enough. If it's any consolation, many questions have a longer shelf life than you might think when other web surfers Google the question and come across your answer. A lot of our traffic is people looking up old questions that have been answered perfectly, even if the original asker has moved on.
    8,323 pointsBadges:
    report
  • carlosdl
    I think the main problem is that people don't provide their real e-mail address. This was my suggestion some weeks ago: When a user posts a question, an e-mail is sent with a link to a confirmation page, and the question gets posted only after the question asker visits that link (confirms the question). A warning about this confirmation should be included in the 'Ask a Question' page. Michael, do you think this would have a negative impact on the site ?
    69,475 pointsBadges:
    report
  • Michael Morisy
    Hi CarlosDL, I really like that idea, particularly if it could be coupled with cutting down the registration process for the site while improving user follow up on questions like this (as we veer startlingly off topic). My only concern is that it would cut down on new, quality users successfully asking questions, and getting the right people to ask the right questions is actually one of the biggest site challenges. I think a simple e-mail confirmation like you suggested might be a good step, however. Thanks for the suggestion, Michael
    8,323 pointsBadges:
    report
  • TomLiotta
    Phil gave a totally precise answer to the question that was asked. To me, though, the question that was asked didn't seem to be the real question. I suspect that even Phil thought that it was too fundamental to be concerned over. Here's a small program that is intended to be run only in debug to explore another kind of solution:
         d newkey          s              5    inz( ' ' )
         d longkey         s             10    inz( '0000001300' )
         d i               s              5u 0 inz( 0 )
    
         d conZeros        c                   '00000'
    
          /free
             dow ( longkey <> 'x' ) ;
                  i         = %len( %trim( longkey )) + 1 ;
                  newkey    = %subst( conZeros + longkey : i : 5 ) ;
             enddo ;
                  *inLR = *on;
          /end-free
    Compile it with DBGVIEW(*ALL) and start debug to put a breakpoint on the ENDDO op-code. Each time through the loop, use EVAL to set longkey to a different value. Set it to 'x' when you want to end the program. (Or make changes to control it however you choose.) The two instructions inside the loop will give '01300' as the result if longkey is '001300', '01300', '000001300' or even '1300'. That is, it is more of a generic solution for a slightly different problem than the one in the question. However, it seems to me to be a more likely problem for a novice programmer to run into than the one asked in the original question. Of course, the question was explicitly about SQLRPGLE. That makes it more confusing without some clarification. It implies that there is a need to tie it in with some SQL statement somehow. I'd gladly post example SQL that better fits the "real" question if I had a good idea what was needed. There is actually quite a bit of discussion that could be associated with this question if we just knew what to discuss. It doesn't seem to make much difference to the OP, but it might make a lot of difference to those who run across this thread in a search a year from now. If you can't search on {trim leading zero sqlrpgle} and get meaningful and appropriate answers, why visit this site more than once? IMO, a verified e-mail address would only improve the quality. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    I don't see much purpose to answering questions that need clarification. Perhaps when we ask for clarification the question should be locked until the original requestor clarifies it, put in a pending status instead of unanswered status. This idea that we're adding to the pool of knowledge .. just don't know about that, I put it all out in my books and they are out of print. Can't sell it, can't even give it away. Phil
    49,950 pointsBadges:
    report
  • TomLiotta
    Perhaps when we ask for clarification the question should be locked until the original requestor clarifies it... That kind of fits with how I've been thinking. A different button like "Request for clarification" should cause a result different from existing buttons. One difference out to be a strong eye-catcher near the top of the page, a change in background color, for example, for the original question. A returning OP would be forcibly notified that something is needed. I wonder how many people come back and see that the 'Answer Wiki' input area is still open. They think nothing has happened and don't continue scrolling down to the discussion area. It's out of sight below. Maybe the existence of discussion should enable a "Read discussion" button that becomes highly visible near the top. Do notification e-mails distinguish between "Answer posted" and "Discussion added"? A clarification request should send a third type of e-mail. As for books, I've got the somewhat sad feeling that a lot of books are no longer needed. On-line forums provide almost everything anyone could want. An obvious but trivial example is how Information Centers have superseded manuals. I still keep my BookManager CDs, but it's been months since I had any reason to keep track of where they are. The last thing I did with any technical books was put them up on bookshelves after our last house move almost ten years ago. And I'm a real book lover. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    We should rate the questions -50 -- This is an unethical question -25 -- This is homework, it will do you a disservice to answer it -10 -- you can find the answer yourself in less than 5 minutes - 0 -- I'll anwser your question but I won't like it +10 -- Question is clear, and the answer is likely to help others +20 -- The answer to this question will change the course of human events
    49,950 pointsBadges:
    report
  • TomLiotta
    We should rate the questions That could be a better idea than rating answers. Discussion often shows that multiple answers are better for different circumstances. Any answer can be technically verified. But how to approach a question about QCTL from someone who hasn't learned about message help? It could be from a small business that's lost technical staff or from someone trying to access something that is off limits. How much should go into an answer? Tom
    125,585 pointsBadges:
    report
  • Michael Morisy
    We had some basic ability to rate questions that we did away with just a few months ago because it saw almost zero use, but please share your ideas in the survey, and we'll try and figure out how to make it all come together.
    8,323 pointsBadges:
    report
  • TomLiotta
    ...please share your ideas in the survey,... I'd already done the survey, but I see it's possible to do it many times. Is there a { Home > IT Answers > |Community questions| } topic area for day-to-day discussion of the site? Tom
    125,585 pointsBadges:
    report
  • YuVa47
    Tom, In the original question was clearly stated that the field is 6A character, so Phil's answer was correct. Why to complicate the answers with questions and examples which are not relevant? YuVa47
    1,300 pointsBadges:
    report
  • philpl1jb
    Thanks, I answered the question but two items in the question are distracting 1. "001300 then I should insert 01300" . this shows two leading zero's and reduces it to one..was that what was really intended? 2. SQLRPGLE was refereced. was the question about how to change the data as part of a select statement? Phil
    49,950 pointsBadges:
    report
  • TomLiotta
    ...6A character... Yes, but is that a program variable? ...an input parm? ...a DSPF field? ...a field from a database file? When the leading zero (if present!) is removed, is the intention to store the value in a different 6A variable or is it in a 5A variable? If it's another 6A variable, should the 5-character value be left- or right-justified? (I actually know of an app that expects right-justified in a 6A column -- a leading single blank!) Let's say it's a program variable containing the value "001300". Is the intent to change that variable to contain "01300b" (where 'b' is blank)? Or is the intent to prepare a value from that variable to be expressed in an INSERT statement so that a table column receives the value "01300"? And if so, is the INSERT applying the value to a 5A field? Or is it going to be a 5-digit numeric field and the OP was confused about how SQL is used in such a case? The question used the word "insert". Is that as in SQL INSERT? Or is it more generic as in inserting a substring of characters into a longer string? Or is simply an unusual way of saying that value goes into another variable? If SQL hadn't been referenced, a number of possibilities would be eliminated. If the destination of the value had been given, other possibilities would be eliminated. Discussion might take us exactly to Phil's answer (probably with the quoted '0 and the "7" replaced with a "5", but those are details). But discussion might also convince the next person who asks a question to ask the question that needs to be answered. We'll never know if we don't make efforts to find out. Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    BTW, the really "correct" answer might be:
    case when substr( InStr,1,1)='A' then substr( InStr,2,5)
         else InStr end
    ...or some variation. Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    Well, "correct" if I didn't also make typos -- =’0’. Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following