how to set PIKMG in delivery to 0? - mapping

In a return order flow i need to:
post reverse goods issue ==> OK
set PIKMG to 0 ==> ko
modify LFIMG and post again the GI ==> OK
I can't find a way to do the second bullet, i tried with BAPI_OUTB_DELIVERY_CHANGE but without success.
Can someone post a good bapi mapping for my requirement or suggest another bapi?
Thank you very much.
Riky

Use WS_DELIVERY_UPDATE_2 BAPI for updating picking quantity.
FM call can look like this:
CALL FUNCTION 'WS_DELIVERY_UPDATE_2'
EXPORTING
vbkok_wa = wa_vbkok " Header Data
synchron = 'X'
commit = 'X'
delivery = vbeln " delivery number
update_picking = 'X'
if_database_update_1 = '1'
TABLES
vbpok_tab = it_vbpok[] " Item Data
prot = it_return. " Message Return Table
CLEAR: deliv_head,wa_vbkok.
READ TABLE it_return INTO wa_return WITH KEY msgty = 'E'.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
* message handling
ENDIF.

Related

I am looking for a Lua find and replace logic

enter image description here
I just started working on lua scripting since a week. I have a lua file where in the logic needs to be written for a certain condition.
The condition when gets triggered
it does an iteration on one of the fields to change value from
(ABC123-XYZ) to this value
(ABC123#1-XYZ) and it keeps increasing whenever iterations happens (ABC123#2-XYZ)
I need to run a function that removes the # followed by number to change it back to (ABC123-XYZ). Looking for any advice!
Edit 1:
Below is the updated code that is written Thanks to #Piglet
I have another scenario if therr are two hashes in the variable.
local x = 'BUS144611111-PNB_00#80901#1555-122TRNHUBUS'
local b = x:gsub("#%d+","")
function remove_char(a) a=a:gsub("#%d+","")
return a;
end if string.match(x,"#")
then print('function')
print(remove_char(x));
else print(x);
end
Expected output should be
x = 'BUS144611111-PNB_00#80901-122TRNHUBUS' for the aforesaid variable
local a = "ABC123#1-XYZ"
local b = a:gsub("#%d+", "")
this will remove any # followed by or one more digits from your string.

how to insert keyword in the step load definition section using python script?

I am using python to insert *Include, Input=file.inp into step load definition section to apply for pressure boundary condition on nodes. Here is my script, however, it is inserted in Part level section. I am wondering how to control the insert position using python. Thanks
def GetKeywordPosition(myModel, blockPrefix, occurrence=1):
if blockPrefix == '':
return len(myModel.keywordBlock.sieBlocks)+1
pos = 0
foundCount = 0
for block in myModel.keywordBlock.sieBlocks:
if string.lower(block[0:len(blockPrefix)])==\
string.lower(blockPrefix):
foundCount = foundCount + 1
if foundCount >= occurrence:
return pos
pos=pos+1
return +1
position = GetKeywordPosition(myModel, '*step')+24
myModel.keywordBlock.synchVersions(storeNodesAndElements=False)
myModel.keywordBlock.insert(position, "\n*INCLUDE, INPUT=file.inp")
You can adapt the re module. This should work
import re
# Get keywordBlock object
kw_block = myModel.keywordBlock
kw_block.synchVersions(storeNodesAndElements=False)
sie_blocks = kw_block.sieBlocks
# Define keywords for the search (don't forget to exclude special symbols with '\')
kw_list = ['\*Step, name="My Step"']
# Find index
idx = 0
for kw in kw_list:
r = re.compile(kw)
full_str = filter(r.match, sie_blocks[idx:])[0]
idx += sie_blocks[idx:].index(full_str)
UPD: Some explanations as requested
As keywords in the .inp file could be somewhat repetitive, the main idea here is to create a "search route", where the last pattern in the list will correspond to a place where you want to make your modifications (for example, if you want to find the "*End" keyword after a specific "*Instance" keyword).
So we proceed iteratively through our "search route" == list of search patterns:
Compile the regex expression;
Find the first appearance of the pattern in the sie_blocks starting from the index idx;
Update the idx so the next search is performed from this point.
Hope this will help

LUA: How to Create 2-dimensional array/table from string

I see several posts about making a string in to a lua table, but my problem is a little different [I think] because there is an additional dimension to the table.
I have a table of tables saved as a file [i have no issue reading the file to a string].
let's say we start from this point:
local tot = "{{1,2,3}, {4,5,6}}"
When I try the answers from other users I end up with:
local OneDtable = {"{1,2,3}, {4,5,6}"}
This is not what i want.
how can i properly create a table, that contains those tables as entries?
Desired result:
TwoDtable = {{1,2,3}, {4,5,6}}
Thanks in advance
You can use the load function to read the content of your string as Lua code.
local myArray = "{{1,2,3}, {4,5,6}}"
local convert = "myTable = " .. myArray
local convertFunction = load(convert)
convertFunction()
print(myTable[1][1])
Now, myTable has the values in a 2-dimensional array.
For a quick solution I suggest going with the load hack, but be aware that this only works if your code happens to be formatted as a Lua table already. Otherwise, you'd have to parse the string yourself.
For example, you could try using lpeg to build a recursive parser. I built something very similar a while ago:
local lpeg = require 'lpeg'
local name = lpeg.R('az')^1 / '\0'
local space = lpeg.S('\t ')^1
local function compile_tuple(...)
return string.char(select('#', ...)) .. table.concat{...}
end
local expression = lpeg.P {
'e';
e = name + lpeg.V 't';
t = '(' * ((lpeg.V 'e' * ',' * space)^0 * lpeg.V 'e') / compile_tuple * ')';
}
local compiled = expression:match '(foo, (a, b), bar)'
print(compiled:byte(1, -1))
Its purpose is to parse things in quotes like the example string (foo, (a, b), bar) and turn it into a binary string describing the structure; most of that happens in the compile_tuple function though, so it should be easy to modify it to do what you want.
What you'd have to adapt:
change name for number (and change the pattern accordingly to lpeg.R('09')^1, without the / '\0')
change the compile_tuple function to a build_table function (local function build_tanle(...) return {...} end should do the trick)
Try it out and see if something else needs to be changed; I might have missed something.
You can read the lpeg manual here if you're curious about how this stuff works.

find Variables in a module

I'm new to DXL and I want to extract the variables containing
_I_,_O_ and _IO_
from a module and export then to csv file. Please help me with this
EG:
ADCD_WE_I_DFGJDGFJ_12_QWE and CVFDFH_AWEQ_I_EHH[X] is set to some value
This question has two parts.
You want to find variables that contain those parts in their name
You want to export to a .csv file
Another person may be able to expand on a better way, but the only way coming to mind right now for 1. is this:
Loop over the attributes in the module (for ad in m do {}) and get the string of the attribute names.
I am assuming that your attributes are valued at _I_, _O_ or _OI_? Like alpha = "_I_"? Are these enumerate values?
If they are, then you only need to check the value of each object's attribute. If one of those are the attribute values, then add it to something like a skip list. Having a counter here would be useful, maybe one for each attribute, like countI, countO, countOI, you can then use the counters as keys for the put() function for the skip list.
Once you have found all the attributes then you can move on to writing to csv
Stream out = write("filepathname/filename.csv") // to declare the stream
out << "_I_, _O_, _OI_\n"
Then you could loop over your Skip lists at the same time
int ijk = 0; bool finito = false
while(!finito) do {
if(ijk<countI) {
at = get(skipListI, ijk)
out << at.name ","
}
else out << ","
if(ijk<countO) {
at = get(skipListO, ijk)
out << at.name ","
}
else out << ","
if(ijk<countOI) {
at = get(skipListOI, ijk)
out << at.name "\n"
}
else out << "\n"
ijk++
// check if the next iteration would be outside of bounds on all lists
if(ijk >= countI && ijk >= countO && ijk >= countIO) finito = true
}
Or instead of at.name, you could print out whatever part of the attribute you wanted. The name, the value, "name:value" or whatever.
I have not run this, so you will be left to do any troubleshooting.
--
I hope this idea gets you started, write out what you want on paper first and then follow that plan. The key things I have mentioned that would be useful here are Skip lists, and Stream write (or append, if you want to keep adding).
In the future, please consider making your question more clear. Are you looking for those search terms in the name of the attribute, or in the value of the attribute. Are you looking to print out the names or the values, or the what? What kind of format for the .csv are you going to have? Any information will help your question be answered.

Foreach loop and hash table with two values:

Example 01 - below is a simplified example of code I am using in a more complicated script.This code works.
THE PROBLEM is that I want to be able to control the order in which the two sets of values - website name and URL - are processed thru the foreach loop.
I UNDERSTAND that hash-tables do not process the data in the order they are listed but rather list it out in a seemingly random fashion.
WHAT HAVE I TRIED:
I've done some research on this via a book, google, and stack exchange.
I have tried using the GetEnumerator command along with its associated "sort name" option as shown in Example 02 below. This example works in this context - it successfully lists the sites according to the alphabetical order of the site name. However I do not want to list alphabetically but rather according to a stipulated order. If the ordering needs to be done manually that will be
fine but I don't see how to achieve this. Furthermore, when I try to use this method with my actual script the script will run but in this section it will display " System.Collections.DictionaryEntry", rather than running the script properly. Maybe I am not running it correctly here.
WHAT ELSE HAVE I TRIED:
I also tried a hash-table using two values - site name and a letter of the alphabet. This successfully listed the sites in the order I had stipulated using letters of the alphabet, BUT my actual script needs to have the two values - website name and URL - to be used in the foreach loop that governs the
running of the script.
I also tried to use three values in the hash-table - thought I may have seen a note that this was possible - however if this is even possible I could not find the syntax to make this work.
FINAL THOUGHT:
I was wondering if you could use two hash-tables to solve this - one to setup the order in which the foreach loop processes the values (as per Example 03 below) and the other to provide the actual values to be used in the foreach loop (as per Example 01).
Is that a possible solution or some alternative ?
Is there any other way to achieve this in a reasonable fashion ?
Thanks in advance.
Example 01
$Sites = #{
'DuckDuckGo' = 'https://duckduckgo.com'
'Google' = 'https://www.google.com'
'Ixquick' = 'https://www.ixquick.com'
'Yahoo ' = 'https://search.yahoo.com'
'Dogpile' = 'http://www.dogpile.com'
'Yippee ' = 'http://www.yippy.com'
}
clear
write-host "`n`n`n"
foreach ($name in $Sites.Keys) {
write-host
"`t`t {0} `t`t`t {1}" -f $name , $Sites[$name]
write-host
}
Example 02
$Sites = #{
'DuckDuckGo' = 'https://duckduckgo.com'
'Google' = 'https://www.google.com'
'Ixquick' = 'https://www.ixquick.com'
'Yahoo ' = 'https://search.yahoo.com'
'Dogpile' = 'http://www.dogpile.com'
'Yippee ' = 'http://www.yippy.com'
}
clear
write-host "`n`n`n"
foreach($name in $Sites.GetEnumerator() | Sort Name)
{
$name
}
write-host "`n`n`n`n"
Example 03
$Sites = #{
'DuckDuckGo' = 'a'
'Google' = 'f'
'Ixquick' = 'c'
'Yahoo ' = 'z'
'Dogpile' = 'e'
'Yippee ' = 'b'
}
$Sites.GetEnumerator() | Sort Value
You're thinking too complicated. Just sort the keys of the hashtable, like this:
$Sites.Keys | Sort-Object | ForEach-Object {
"{0}`t{1}" -f $_, $Sites[$_]
}
or like this:
foreach ($name in ($Sites.Keys | Sort-Object)) {
"{0}`t{1}" -f $name, $Sites[$name]
}
If you want the elements of the hashtable to be in a particular order from the start create an ordered hashtable:
$Sites = [ordered]#{
'DuckDuckGo' = 'https://duckduckgo.com'
'Google' = 'https://www.google.com'
'Ixquick' = 'https://www.ixquick.com'
'Yahoo ' = 'https://search.yahoo.com'
'Dogpile' = 'http://www.dogpile.com'
'Yippee ' = 'http://www.yippy.com'
}
As a side note: don't mix Write-Host and PowerShell default output (echoing of bare strings). They do different things. The latter writes to the success output stream, whereas the former writes to the host console. The order in which host and stream output are displayed may be different from what you expect.

Resources